import os
import matplotlib.pyplot as plt
from matplotlib import pyplot
import numpy as np
from scipy import interpolate
import torchaudio
import torch

def zhexiantu():
    lines = 0
    Epoch1 = []
    VEER1 = []
    with open("../exps/ST_ResNetSE34L_log_FA_80/result/scores.txt", "r") as f:
        for line in f.readlines():
            lines += 1
            data = line.strip().split(" ")
            # floatdata = map(float, data)
            if (lines % 6 == 0):
                # print(data)
                # print(floatdata[1])
                Epoch1.append(int(data[1][0:-1]))
                VEER1.append(float(data[3][0:-1]))

        # print(Epoch)
        # print(VEER)
    Epoch = []
    VEER = []
    lines = 0
    with open("../exps/ST_ResNetSE34L_log_80/result/scores.txt", "r") as f:
        for line in f.readlines():
            lines += 1
            data = line.strip().split(" ")

            if (lines % 6 == 0):
                # print(data)
                Epoch.append(int(data[1][0:-1]))
                VEER.append(float(data[3][0:-1]))
    Epoch2 = []
    VEER2 = []
    lines = 0
    with open("../exps/ST_ResNetSE34L_log_MA_80_0/result/scores.txt", "r") as f:
    # with open("exps/新建文本文档.txt", "r") as f:
        for line in f.readlines():
            lines += 1
            data = line.strip().split(" ")
            # floatdata = map(float, data)
            if (lines % 6 == 0):
                # print(data)
                # print(floatdata[1])
                Epoch2.append(int(data[1][0:-1]))
                VEER2.append(float(data[3][0:-1]))

    # pyplot.figure(figsize=(6, 4.5))
    # plt.style.use('seaborn-whitegrid')
    palette = pyplot.get_cmap('Set1')
    # plt.rcParams.update({'font.size': 12})

    x = Epoch[0:30]

    y_0 = VEER[0:30]
    # y_FA = VEER1[0:30]
    y_MA = VEER2[0:30]

    plt.plot(x, y_0, color=palette(0), marker='o', label='Original')
    # plt.plot(x, y_FA, color=palette(1), marker='^', label='Frequency attention')
    plt.plot(x, y_MA, color=palette(2), marker='s', label='Multichannel')

    plt.legend()  # 让图例生效

    plt.xlabel('Epoch')  # X轴标签
    plt.ylabel("EER")  # Y轴标签
    plt.show()
    # plt.savefig('MultiLOSS', dpi=300)

def FAweight():

    weight = []
    with open("quanzhong.txt", "r") as f:
        # with open("exps/新建文本文档.txt", "r") as f:
        for line in f.readlines():

            # data = line.strip().split("\n")
            data = line.strip()
            # floatdata = map(float, data)
            # print(data)
            weight.append(float(data[1:-2]))
        print(weight)

def putu():
    torchfb = torchaudio.transforms.MelSpectrogram(sample_rate=16000, n_fft=512, win_length=400,
                                         hop_length=160, window_fn=torch.hamming_window,
                                         n_mels=80)

    wav = open("D:\\dataset\\ST-CMDS-20170001_1-OS\\ST-CMDS-20170001_1-OS\\20170001P00001A0001.wav")

    print(np.shape(wav))
    mel = torchfb(wav) + 1e-6
    mel = mel.log()

    plt.figure('谱图')
    x = mel
    plt.imshow(x[0][0].detach().numpy())
    plt.show()
    # plt.savefig('png/jiaquan谱图', dpi=300)


if __name__ == '__main__':
    putu()
